package com.portal.cwegportal.controller;

import com.appcenter.jz.Logger.BusinessLogger;
import com.appcenter.jz.Logger.LoggerGenre;
import com.appcenter.jz.config.ErrorJsonResult;
import com.appcenter.jz.config.JsonResult;
import com.portal.cwegportal.input.columnplate.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("api/services/portal/columnplate")
@Api(description = "栏目与板块API")
public class ColumnPlateController {
    @Autowired
    com.portal.cwegportal.service.ColumnPlateService columnPlateService;

    @ApiOperation(value = "创建栏目与板块", notes = "创建栏目与板块", produces = "application/json")
    @PostMapping("/createColumnPlate")
    public ResponseEntity<JsonResult> createColumnPlate(@RequestBody CreateColumnPlateInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        BusinessLogger.Info( LoggerGenre.Add,"创建栏目与板块",input);
        JsonResult r = new JsonResult();

        try {
            r.setResult(columnPlateService.createColumnPlate(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(200).body(r);
        }
        return ResponseEntity.ok(r);
    }


    @ApiOperation(value = "删除栏目与板块", notes = "删除栏目与板块",produces = "application/json")
    @PostMapping("/deleteColumnPlate")
    public ResponseEntity<JsonResult> deleteColumnPlate(@RequestBody DeleteColumnPlateInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        BusinessLogger.Info( LoggerGenre.Add,"删除栏目与板块",input);
        JsonResult r = new JsonResult();
        try {
            r.setResult(columnPlateService.deleteColumnPlate(input));

        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(200).body(r);
        }
        return ResponseEntity.ok(r);
    }


    @ApiOperation(value = "修改栏目与板块", notes = "修改栏目与板块",produces = "application/json")
    @PostMapping("/editColumnPlate")
    public ResponseEntity<JsonResult> editColumnPlate(@RequestBody EditColumnPlateInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        BusinessLogger.Info( LoggerGenre.Add,"修改栏目与板块",input);
        JsonResult r = new JsonResult();
        try {
            r.setResult(columnPlateService.editColumnPlate(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(200).body(r);
        }
        return ResponseEntity.ok(r);
    }

    @ApiOperation(value = "搜索栏目与板块", notes = "搜索栏目与板块",produces = "application/json")
    @PostMapping("/getColumnPlate")
    public ResponseEntity<JsonResult> getColumnPlate(@RequestBody GetColumnPlatesInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        BusinessLogger.Info( LoggerGenre.Add,"搜索栏目与板块",input);
        JsonResult r = new JsonResult();

        try {
            r.setResult(columnPlateService.getColumnPlates(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(200).body(r);
        }

        return ResponseEntity.ok(r);
    }

    @ApiOperation(value = "加载栏目与板块信息", notes = "加载栏目与板块信息",produces = "application/json")
    @PostMapping("/pageLoad")
    public ResponseEntity<JsonResult> pageLoad(@RequestBody PageLoadInput input) throws Exception {
        BusinessLogger.Info( LoggerGenre.Add,"加载栏目与板块信息",input);
        JsonResult r = new JsonResult();
        try {
            r.setResult(columnPlateService.pageLoad(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(200).body(r);
        }
        return ResponseEntity.ok(r);
    }

    @ApiOperation(value = "加载栏目与板块信息(不分页)", notes = "加载栏目与板块信息(不分页)",produces = "application/json")
    @PostMapping("/getAllColumnPlates")
    public ResponseEntity<JsonResult> getAllColumnPlatesByKeyType(@RequestBody GetAllColumnPlatesInput input) throws Exception {
        BusinessLogger.Info( LoggerGenre.Add,"加载栏目与板块信息(不分页)",input);
        JsonResult r = new JsonResult();
        try {
            r.setResult(columnPlateService.getAllColumnPlates(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(200).body(r);
        }
        return ResponseEntity.ok(r);
    }
}
